﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WF.Model;
using WF.DAL;

namespace WF.BusinessObject
{
    /// <summary>
    /// WF_ApplyInstance业务对象
    /// </summary>
    public class WF_ApplyInstance : BOBase<WF_ApplyInstanceEntity, DAL.WF_ApplyInstance>
    {
        #region 构造函数

        public WF_ApplyInstance() : base() { }
        public WF_ApplyInstance(WFDBDataContext DataContext) : base(DataContext) { }
        #endregion

        #region 实现基类abstract方法
        /// <summary>
        /// 实现基类的GetById abstract方法
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public override WF_ApplyInstanceEntity GetById(string ID)
        {
            var obj = DataContext.WF_ApplyInstances.SingleOrDefault(o => o.ApplyID == ID);
            return new WF_ApplyInstanceEntity(obj);
        }
        #endregion

        #region Public 方法
        public List<WF_ApplyInstanceEntity> GetAll()
        {
            var target = DataContext.WF_ApplyInstances.ToList();
            List<WF_ApplyInstanceEntity> result = new List<WF_ApplyInstanceEntity>();
            foreach (var item in target)
            {
                result.Add(new WF_ApplyInstanceEntity(item));
            }
            return result;
        }
        #endregion

        #region WF_ApplyInstance
        /// <summary>
        /// Get All WF_ApplyInstance
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public bool GetAllWF_ApplyInstanceEntity(out List<WF_ApplyInstanceEntity> result)
        {
            var target = DataContext.WF_ApplyInstances.ToList();
            result = new List<WF_ApplyInstanceEntity>();
            foreach (var item in target)
            {
                result.Add(new WF_ApplyInstanceEntity(item));
            }

            return true;
        }

        ///// <summary>
        ///// Get WF_ApplyInstanceEntityById
        ///// </summary>
        ///// <param name="p"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public bool GetWF_ApplyInstanceEntityById(string p, out WF_ApplyInstanceEntity result)
        //{
        //    DAL.WF_ApplyInstance wfAppInstance = DataContext.WF_ApplyInstances.SingleOrDefault(obj => obj.ApplyID == p);
        //    result = new WF_ApplyInstanceEntity(wfAppInstance);

        //    return true;
        //}
        ///// <summary>
        ///// Add
        ///// </summary>
        ///// <param name="wF_ApplyInstanceEntity"></param>
        ///// <returns></returns>
        //public bool Add(WF_ApplyInstanceEntity wF_ApplyInstanceEntity)
        //{
        //    DAL.WF_ApplyInstance wf_applyInstance = new DAL.WF_ApplyInstance();
        //    if (wF_ApplyInstanceEntity.ID == null || wF_ApplyInstanceEntity.ID == String.Empty)
        //        wf_applyInstance.ApplyID = System.Guid.NewGuid().ToString();
        //    else
        //        wf_applyInstance.ApplyID = wF_ApplyInstanceEntity.ID;
        //    wf_applyInstance.ApplyTypeID = wF_ApplyInstanceEntity.ApplyTypeID;
        //    wf_applyInstance.BizDataID = wF_ApplyInstanceEntity.BizDataID;
        //    wf_applyInstance.ApplyBy = wF_ApplyInstanceEntity.ApplyBy;
        //    wf_applyInstance.CurState = wF_ApplyInstanceEntity.CurState;
        //    wf_applyInstance.ApplyBy = wF_ApplyInstanceEntity.ApplyBy;
        //    wf_applyInstance.ApplicantName = wF_ApplyInstanceEntity.ApplicantName;
        //    wf_applyInstance.ApplyDeptID = wF_ApplyInstanceEntity.ApplyDeptID;
        //    wf_applyInstance.ApplyDate = wF_ApplyInstanceEntity.ApplyDate;
        //    wf_applyInstance.K2SN = wF_ApplyInstanceEntity.K2SN;
        //    wf_applyInstance.IsWFSubmit = wF_ApplyInstanceEntity.IsWFSubmit;
        //    wf_applyInstance.IsFinished = wF_ApplyInstanceEntity.IsFinished;
        //    wf_applyInstance.ProcInstID = wF_ApplyInstanceEntity.ProcInstID;
        //    wf_applyInstance.CurrentStepOrder = wF_ApplyInstanceEntity.CurrentStepOrder;
        //    wf_applyInstance.IsFinished = wF_ApplyInstanceEntity.IsFinished;
        //    wf_applyInstance.ApplyEmpID = wF_ApplyInstanceEntity.ApplyEmpID;

        //    DataContext.WF_ApplyInstances.InsertOnSubmit(wf_applyInstance);
        //    DataContext.SubmitChanges();

        //    return true;
        //}

        ///// <summary>
        ///// update
        ///// </summary>
        ///// <param name="wF_ApplyInstanceEntity"></param>
        ///// <returns></returns>
        //public bool Update(WF_ApplyInstanceEntity wF_ApplyInstanceEntity)
        //{
        //    DAL.WF_ApplyInstance wf_applyInstance = DataContext.WF_ApplyInstances.SingleOrDefault(obj => obj.ApplyID == wF_ApplyInstanceEntity.ID);
        //    if (wf_applyInstance == null) return false;
        //    wf_applyInstance.ApplyTypeID = wF_ApplyInstanceEntity.ApplyTypeID;
        //    wf_applyInstance.BizDataID = wF_ApplyInstanceEntity.BizDataID;
        //    wf_applyInstance.ApplyBy = wF_ApplyInstanceEntity.ApplyBy;
        //    wf_applyInstance.CurState = wF_ApplyInstanceEntity.CurState;
        //    wf_applyInstance.ApplyBy = wF_ApplyInstanceEntity.ApplyBy;
        //    wf_applyInstance.ApplicantName = wF_ApplyInstanceEntity.ApplicantName;
        //    wf_applyInstance.ApplyDeptID = wF_ApplyInstanceEntity.ApplyDeptID;
        //    wf_applyInstance.ApplyDate = wF_ApplyInstanceEntity.ApplyDate;
        //    wf_applyInstance.K2SN = wF_ApplyInstanceEntity.K2SN;
        //    wf_applyInstance.IsWFSubmit = wF_ApplyInstanceEntity.IsWFSubmit;
        //    wf_applyInstance.IsFinished = wF_ApplyInstanceEntity.IsFinished;
        //    wf_applyInstance.ProcInstID = wF_ApplyInstanceEntity.ProcInstID;
        //    wf_applyInstance.CurrentStepOrder = wF_ApplyInstanceEntity.CurrentStepOrder;
        //    wf_applyInstance.IsFinished = wF_ApplyInstanceEntity.IsFinished;
        //    wf_applyInstance.ApplyEmpID = wF_ApplyInstanceEntity.ApplyEmpID;

        //    DataContext.WF_ApplyInstances.InsertOnSubmit(wf_applyInstance);
        //    DataContext.SubmitChanges();

        //    return true;
        //}

        ///// <summary>
        ///// delete
        ///// </summary>
        ///// <param name="p"></param>
        ///// <returns></returns>
        //public bool DeleteApplyInstanceEntity(string p)
        //{

        //    DAL.WF_ApplyInstance sysset = DataContext.WF_ApplyInstances.SingleOrDefault(obj => obj.ApplyID == p);
        //    if (sysset != null)
        //    {
        //        DataContext.WF_ApplyInstances.DeleteOnSubmit(sysset);
        //        DataContext.SubmitChanges();
        //    }

        //    return true;
        //}
        #endregion

        internal WF_ApplyInstanceEntity GetByBizDataID(string bizDataID)
        {
            var target = DataContext.WF_ApplyInstances.SingleOrDefault(obj => obj.BizDataID == bizDataID);
            return new WF_ApplyInstanceEntity(target);
        }

        internal WF_ApplyInstanceEntity GetByProcInstID(int p)
        {
            var target = DataContext.WF_ApplyInstances.SingleOrDefault(obj => obj.ProcInstID == p);
            return new WF_ApplyInstanceEntity(target);

            //var obj = from a in DataContext.WF_ApplyInstances
            //          where a.ProcInstID == p
            //          select a;
            //foreach (var item in obj)
            //{
            //    return (new WF_ApplyInstanceEntity(item));
            //}
            //return null;
        }


    }
}
